/*!
 * FileName: poj-1655.cpp
 * This Problem is on poj. The ID of the problem is 1655. 
 * Copyright(c) 2019 Shu_Yu_Mo
 * MIT Licensed
 * Luogu: https://www.luogu.org/space/show?uid=44615
 * Github: https://github.com/oldsuold/
 * Gitee: https://gitee.com/Shu_Yu_Mo/
 * These words were created by an amazing tool written by Shu_Yu_Mo.
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int _N = 201000;
inline int read()
{
    char c = getchar(); int sign = 1; int x = 0;
    while(c > '9' || c < '0') { if(c=='-')sign = -1; c = getchar(); } 
    while(c <= '9' && c >= '0') { x *= 10; x += c - '0'; c = getchar(); }
    return x * sign;
}
struct edges{
	int node;
	int nxt;
}edge[_N];
int head[_N];
int tot = 0;
void add(int u, int v)
{
	edge[++tot].nxt = head[u];
	edge[tot].node = v;
	head[u] = tot;
}
int n;
int AnsId;
int minSize = inf;
int Size[_N];
void dfs(int now, int parent)
{
	int res = 0;
	Size[now] = 1;
	for(register int i = head[now];i;i = edge[i].nxt)
	{
		int sonNode = edge[i].node;
		if(sonNode == parent) continue;
		dfs(sonNode, now);
		Size[now] += Size[sonNode];
		res = max(res, Size[sonNode]);
	}
	res = max(res, n - Size[now]);
	if(res == minSize)
		AnsId = min(AnsId, now);
	else if(res < minSize)
		AnsId = now, minSize = res;
	return;
}
void doit()
{
	memset(Size, 0, sizeof(Size));
	minSize = inf;
	n = read();
	int k;
	memset(head, 0, sizeof(head));
	tot = 0;
	for(register int i = 1;i <= n - 1;i ++)
	{
		int tmpx = read(), tmpy = read();
		add(tmpx, tmpy);
		add(tmpy, tmpx);
		k = tmpx;
	}
	dfs(k, 0);
	printf("%d %d\n", AnsId, minSize) ;
}
int main()
{
	int T = read();
	while(T--)
	{
		doit();
	}
    return 0;
}
